package com.incms.web.common.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="/common")
@ControllerAdvice
public class commonController extends BaseController {
	
	@Value(value="${debug}")
	public Boolean debug = false;
	
	@ExceptionHandler(value = Exception.class)  
	@RequestMapping(value = "/error")
	public ModelAndView error500(HttpServletRequest req, Exception e){
		ModelAndView view = new ModelAndView("/common/error500");
		if(e instanceof UnauthorizedException){
			view.setViewName("/common/unauthorized");
		}
		view.addObject("exception", e);
		view.addObject("req",req);
		view.addObject("debug",debug);
		return view;
	}

	/**
	 * 资源不存在
	 */
	@RequestMapping("/error404")
	public String resourceNotFound() {
		System.out.println("error404");
		return "/common/error404";
	}
	
	@RequestMapping("/unauthorized")
	public String unauthorized(){
		return "/common/unauthorized";
	}

}
